<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


<div id="app1">
    <h1>{{info.name}}</h1>
    <h2>{{info.age}}</h2>
    <li v-for="item in info.happys">{{item.name}},{{item.type}}</li>
</div>

<h1>8.计算函数</h1>
<div id="app8">
    <textarea v-model="message"></textarea>
    <span>{{message}}</span>
    <span>{{currentTime}}</span>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    var vm = new Vue({
        el: "#app1",
        mounted(){
             axios.get("../data.json").then(response=>(this.info=response.data))
        },
        data(){
            return{
                info:{
                    name:null,
                    age:null,
                    happys:[]
                }
            }
        }
    })

    var vm8 = new Vue({
        el:"#app8",
        data:{
            message:""
        },
        computed:{
            currentTime:function (){  //计算函数currentTime的结果是放到内存中的，只有在messages刷新的时候（其中一个元素变化）
                                      // 才能重新计算此方法的值
                this.message;
                return Date.now();
            }
        }
    })

</script>
</body>
</html>